// api.js

import { httpRequest } from "./request.js";

// 封装GET请求
export const get = async (url, params = {}) => {
    try {
        return await httpRequest(url, params, "GET");
    } catch (error) {
        console.error('GET请求失败', error);
        throw error; // 抛出异常，交由调用方处理
    }
};

// 封装POST请求
export const post = async (url, data = {}) => {
    try {
        return await httpRequest(url, data, "POST");
    } catch (error) {
        console.error('POST请求失败', error);
        throw error; // 抛出异常，交由调用方处理
    }
};

// 封装PUT请求
export const put = async (url, data = {}) => {
    try {
        return await httpRequest(url, data, "PUT");
    } catch (error) {
        console.error('PUT请求失败', error);
        throw error; // 抛出异常，交由调用方处理
    }
};

// 封装DELETE请求
export const del = async (url, params = {}) => {
    try {
        return await httpRequest(url, params, "DELETE");
    } catch (error) {
        console.error('DELETE请求失败', error);
        throw error; // 抛出异常，交由调用方处理
    }
};
